:root {
    --user-bubble: rgba(100, 149, 237, 0.66);
    --ai-bubble: rgba(255, 248, 220, 0.66);
    --text-color: #1c1c1e;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text-color);
    background: url('back.jpg') center/cover no-repeat fixed;
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    height: 100dvh;
    height: 100vh;
    display: flex;
    justify-content: center;
    font-size: clamp(16.1px, 2.875vw, 20.7px);
    overflow: hidden;
}

.chat-app {
    width: 100%;
    height: 100%;
    background: transparent;
}

.floating-title {
    position: fixed;
    top: env(safe-area-inset-top);
    left: 0;
    right: 0;
    z-index: 10;
    padding: clamp(8px, 2vh, 16px) clamp(10px, 4vw, 20px);
    background: linear-gradient(to top, 
        rgba(0,0,0,0) 0%, 
        rgba(0,0,0,0.1) 30%,
        rgba(0,0,0,0.3) 60%,
        rgba(0,0,0,0.5) 85%,
        rgba(0,0,0,0.66) 100%
    );
    color: white;
    text-align: center;
    pointer-events: none;
    isolation: isolate;
}

.floating-title::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: -1;
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    -webkit-mask-image: linear-gradient(to top, 
        rgba(0,0,0,0) 0%, 
        rgba(0,0,0,0.1) 30%,
        rgba(0,0,0,0.3) 60%,
        rgba(0,0,0,0.5) 85%,
        rgba(0,0,0,0.66) 100%
    );
    mask-image: linear-gradient(to top, 
        rgba(0,0,0,0) 0%, 
        rgba(0,0,0,0.1) 30%,
        rgba(0,0,0,0.3) 60%,
        rgba(0,0,0,0.5) 85%,
        rgba(0,0,0,0.66) 100%
    );
}

.floating-title h1 {
    font-size: clamp(1.47em, 5.33vw, 1.87em);
    font-weight: 600;
    margin: 0;
}

.floating-title h1 .emoji {
    background: none;
    -webkit-background-clip: unset;
    -webkit-text-fill-color: unset;
    background-clip: unset;
}

.floating-title h1 .name {
    background: linear-gradient(135deg, #ff8c00, #ff0000);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.floating-title p {
    font-size: clamp(0.65em, 2.5vw, 0.8em);
    opacity: 0.8;
    margin: clamp(2px, 0.5vh, 4px) 0 0;
    height: clamp(14px, 3vh, 20px);
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-messages {
    overflow-y: auto;
    padding-top: clamp(60px, 15vh, 80px);
    padding-bottom: clamp(90px, 20vh, 120px);
    padding-left: calc(clamp(10px, 3vw, 20px) + env(safe-area-inset-left));
    padding-right: calc(clamp(10px, 3vw, 20px) + env(safe-area-inset-right));
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: clamp(10px, 2vh, 16px);
}

@keyframes bubble-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-bubble {
    max-width: min(80%, 90vw);
    padding: clamp(0.5rem, 0.75rem, 0.75rem) clamp(0.75rem, 1rem, 1.125rem);
    border-radius: clamp(0.875rem, 1.125rem, 1.375rem);
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-size: clamp(0.805rem, 0.92rem, 1.035rem);
    animation: bubble-in 0.3s ease-out forwards;
}

@media (orientation: landscape) {
    .message-bubble {
        max-width: 55%;
    }
}

.message-bubble.user {
    background: var(--user-bubble);
    align-self: flex-end;
    border-bottom-right-radius: clamp(4px, 1vw, 6px);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.message-bubble.ai {
    background: var(--ai-bubble);
    align-self: flex-start;
    border-bottom-left-radius: clamp(4px, 1vw, 6px);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.message-bubble.amnesia {
    background: rgba(210, 105, 30, 0.66);
    align-self: flex-start;
    border-bottom-left-radius: clamp(4px, 1vw, 6px);
    backdrop-filter: blur(5px);
}

.chat-input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: clamp(8px, 1.5vh, 10px);
    padding-left: calc(clamp(10px, 3vw, 15px) + env(safe-area-inset-left));
    padding-right: calc(clamp(10px, 3vw, 15px) + env(safe-area-inset-right));
    padding-bottom: calc(clamp(8px, 1.5vh, 10px) + env(safe-area-inset-bottom));
    background: transparent;
    justify-content: center;
}

#user-input {
    flex: 1;
    border: none;
    border-radius: clamp(14px, 3.5vw, 20px);
    padding: 10px 18px;
    font-size: clamp(14px, 2.5vw, 16px);
    background: rgba(255, 255, 255, 0.66);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    outline: none;
    height: 48px;
}

#send-button {
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    width: 85px;
    height: 85px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent; 
}

#send-button:active {
    transform: none;
}

#send-button img {
    width: 64px;
    height: 64px;
}

.loading-indicator {
    display: flex;
    gap: 5px;
    padding: 10px 15px;
    min-height: 40px;
    align-items: center;
}

.loading-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-color);
    border-radius: 50%;
    animation: pulse 1.2s infinite;
}

.loading-indicator span:nth-child(2) { animation-delay: 0.2s; }
.loading-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}